package com.cq.hd.app.controller;

import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.Throw;
import com.cq.hd.member.api.TbConfigSettingApi;
import com.cq.hd.member.api.dto.ConfigSettingUpdateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@RequestMapping("/configSetting")
@Api(tags = "配置")
public class ConfigSettingController extends BaseController {

    @Resource
    private TbConfigSettingApi configSettingApi;

    @ApiOperation(value = "用户配置key更新")
    @PostMapping("/save")
    public Result<Void> set(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                            @RequestBody ConfigSettingUpdateDto configSettingUpdateDto) {
        if (appLoginUser == null) {
            Throw.isBusinessException("请先登录");
        }
        configSettingUpdateDto.setUserId(appLoginUser.getUserId());
        return configSettingApi.setConfigValue(configSettingUpdateDto);
    }

}
